/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ExcelAccess;

import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 *
 * @author workshop
 */
public class ExcelFormat {
    public static String[] objectsFields = {"Object","Ordernumber","Client","Vessel","Equipment","Year Built"};
    public static String[] serviceCallFields = 
    {"object","Service No.","Call No.","Status","Responsible","Type of Issue","Priority","Attended By",
    "Location","Date","Reason","Involve System","Down Time","Root Cause Group","Root Cause",
    "Rectification","Repair Time","Part Replaced","Part Brand","Part Manuf Number","Part Isah Number",
    "Service Report","Recommendations","Remarks"};
    
    public static String[] convertFieldNames(String[] fields){
        if(fields == null) return null;
        String[] result = new String[fields.length];
        for(int i = 0; i < fields.length; i++){
            result[i] = convertFieldNames(fields[i]);
        }
        return result;
    }
    
    private static String convertFieldNames(String input){
        if(input == null) return null;
        if(input.isEmpty()) return "";
        StringTokenizer st = new StringTokenizer(input);
        int numTokens = st.countTokens();
        String result = st.nextToken();
        for(int i = 1; i < numTokens; i++){
            result += "_" + st.nextToken();
        }
        return result;
    }
    
    public static ArrayList<String> convertFieldNames(ArrayList<String> fields){
        if(fields == null) return null;
        ArrayList<String> result = new ArrayList<>();
        for(int i = 0; i < fields.size(); i++){
            result.add(convertFieldNames(fields.get(i)));
        }
        return result;
    }
    
    private static String addBackSlashSQL(String value){
        if(value == null) return null;
        if(value.isEmpty()) return "";
        StringTokenizer st = new StringTokenizer(value,"\\");
        int numTokens = st.countTokens();
        String result = st.nextToken();
        for(int i = 1; i < numTokens; i++){
            result += "\\\\" + st.nextToken();
        }
        if(value.startsWith("\\\\")){
            result = "\\\\\\\\" + result;
        }
        return result;
    }
    
    public static ArrayList<String> addBackSlashSQL(ArrayList<String> values){
        if(values == null) return null;
        ArrayList<String> result = new ArrayList<>();
        for(int i = 0; i < values.size(); i++){
            result.add(addBackSlashSQL(values.get(i)));
        }
        return result;
    }
    
    public static int getNumNonEmptyElement(ArrayList<String> Val){
        int result = 0;
        for(int i = 0; i < Val.size(); i++){
            if(!Val.get(i).isEmpty()) result++;
        }
        return result;
    }
}
